package cn.dankal.lequ.ui.fragment.gamedetails_fragment;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.HorizontalScrollView;
import android.widget.ImageView;
import android.widget.TextView;

import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;
import cn.dankal.lequ.R;
import cn.dankal.lequ.ui.activity.MyPicViewPager;

/**
 * 作者： fred on 16/4/19 11:21.
 * 邮箱：fred_kang@dankal.cn
 */
public class Details_Fragment extends Fragment {
    boolean expand1 = true;
    boolean expand2 = true;
    @Bind(R.id.scroll)
    HorizontalScrollView scroll;
    @Bind(R.id.tv_game_introduce)
    TextView tv_game_introduce;
    @Bind(R.id.tv_update)
    TextView tv_update;
    @Bind(R.id.v1)
    View v1;
    @Bind(R.id.v2)
    View v2;

    @Bind(R.id.tv_update_more)
    TextView tv_update_more;
    @Bind(R.id.tv_game_introduce_more)
    TextView tv_game_introduce_more;
    @Bind(R.id.iv1)
    ImageView iv1;

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_gamedetails_details, container, false);
        ButterKnife.bind(this, view);
        tv_game_introduce.post(new Runnable() {
            @Override
            public void run() {
                if (tv_game_introduce.getLineCount() > 3) {
                    v1.setVisibility(View.VISIBLE);
                    tv_game_introduce_more.setVisibility(View.VISIBLE);
                }
            }
        });

        tv_update.post(new Runnable() {
            @Override
            public void run() {
                tv_update.getLineCount();
                if (tv_update.getLineCount() > 3) {
                    v2.setVisibility(View.VISIBLE);
                    tv_update_more.setVisibility(View.VISIBLE);
                }
            }
        });
        return view;
    }

    @Override
    public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
    }

    @OnClick({R.id.tv_update_more, R.id.tv_game_introduce_more, R.id.tv_moregame, R.id.iv1, R.id.iv2})
    public void textViewClick(View view) {
        switch (view.getId()) {
            case R.id.tv_update_more:
                if (expand1) {
                    tv_update.setMaxLines(tv_game_introduce.getLineCount());
                    expand1 = false;
                    tv_update_more.setText("关闭全文");

                } else {
                    tv_update.setMaxLines(3);
                    expand1 = true;
                    tv_update_more.setText("展开全文");

                }

                break;
            case R.id.tv_game_introduce_more:
                if (expand2) {
                    tv_game_introduce.setMaxLines(tv_game_introduce.getLineCount());
                    expand2 = false;
                    tv_game_introduce_more.setText("关闭全文");
                } else {
                    tv_game_introduce.setMaxLines(3);
                    expand2 = true;
                    tv_game_introduce_more.setText("展开全文");
                }
                break;
            case R.id.tv_moregame:
                break;
            case R.id.iv1:
                Intent intent = new Intent(this.getActivity(), MyPicViewPager.class);
                intent.putExtra("pagePosition", 0);
                startActivity(intent);
                break;
            case R.id.iv2:
                Intent intent1 = new Intent(this.getActivity(), MyPicViewPager.class);
                intent1.putExtra("pagePosition", 1);
                startActivity(intent1);
                break;


            default:
                break;
        }

    }

}
